# -*- coding: utf-8 -*-

from reportlab.lib.pagesizes import A4
from reportlab.lib.units import cm
from reportlab.lib.enums import TA_CENTER, TA_RIGHT

from geraldo import Report, ReportBand, Label, ObjectValue, SystemField,\
                    BAND_WIDTH, ReportGroup, FIELD_ACTION_COUNT

class RelatorioAcaoJudicialGeralPDF(Report):
#    title = 'Relatório Geral dos Servidores de Ações Judiciais'
    author = 'CBTU - Companhia Brasileira de Trens Urbanos'
    
    print_if_empty = True
    page_size = A4

    class band_page_header(ReportBand):
        height = 1.75*cm
        elements = [
            SystemField(expression='%(var:titulo)s', top=0, left=0, width=BAND_WIDTH,
                style={'fontName': 'Helvetica-Bold', 'fontSize': 14, 'alignment': TA_CENTER}),
            Label(text="NOME", top=1.2*cm, left=0*cm, width=11*cm,
                  style={'alignment':TA_CENTER}, borders={'bottom': True}),
            Label(text="MATRÍCULA", top=1.2*cm, left=11.1*cm, width=4*cm,
                  style={'alignment':TA_CENTER}, borders={'bottom': True}),
            Label(text="GRUPO", top=1.2*cm, left=15.2*cm, width=3.8*cm,
                  style={'alignment':TA_CENTER}, borders={'bottom': True}),
        ]
#        borders = {'bottom': True, 'top': True}

    class band_page_footer(ReportBand):
        height = 0.5*cm
        elements = [
            SystemField(expression='%(report_author)s', top=0.1*cm, left=0, width=30*cm),
            SystemField(expression='Página # %(page_number)d de %(page_count)d', top=0.1*cm,
                width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
        ]
        borders = {'top': True}

    class band_detail(ReportBand):
        auto_expand_height = True
        force_new_page = True
        elements = [
            ObjectValue(attribute_name='nome', left=0*cm, width=11*cm,
                  style={'alignment':TA_CENTER}, borders={'top': True}),
            ObjectValue(attribute_name='matricula', left=11.1*cm, width=4*cm,
                  style={'alignment':TA_CENTER}, borders={'top': True}),
            ObjectValue(attribute_name='descricao', left=15.2*cm, width=3.8*cm,
                  style={'alignment':TA_CENTER}, borders={'top': True}),
        ]
    groups = [
              ReportGroup(attribute_name='descricao',
                          band_header=ReportBand(
                                            height=0.7*cm,
                                            elements=[
                                                ObjectValue(attribute_name='descricao', left=0, top=0.1*cm,
                                                    style={'fontName': 'Helvetica-Bold', 'fontSize': 12})
                                                        ],
                                                    ),
                          band_footer=ReportBand(
                                            height=0.7*cm,
                                            elements=[
                                                ObjectValue(attribute_name='nome', action=FIELD_ACTION_COUNT,
                                                    display_format='%s Servidor(es)', left=0*cm, top=0.25*cm)
                                                        ],
                                                        borders={'bottom': True},
                                            ),
                          ),
              ]



class RelatorioAcaoJudicialPDF(Report):
#    title = 'Relatório Geral dos Servidores de Ações Judiciais'
    author = 'CBTU - Companhia Brasileira de Trens Urbanos'
    
    print_if_empty = True
    page_size = A4

    class band_page_header(ReportBand):
        height = 1.75*cm
        elements = [
            SystemField(expression='%(var:titulo)s', top=0, left=0, width=BAND_WIDTH,
                style={'fontName': 'Helvetica-Bold', 'fontSize': 14, 'alignment': TA_CENTER}),
            Label(text="NOME", top=1*cm, left=0*cm, width=11*cm,
                  style={'alignment':TA_CENTER}, borders={'bottom': True}),
            Label(text="MATRÍCULA", top=1*cm, left=11.1*cm, width=4*cm,
                  style={'alignment':TA_CENTER}, borders={'bottom': True}),
            Label(text="GRUPO", top=1*cm, left=15.2*cm, width=3.8*cm,
                  style={'alignment':TA_CENTER}, borders={'bottom': True}),
        ]

    class band_page_footer(ReportBand):
        height = 0.5*cm
        elements = [
            SystemField(expression='%(report_author)s', top=0.1*cm, left=0, width=30*cm),
            SystemField(expression='Página # %(page_number)d de %(page_count)d', top=0.1*cm,
                width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
        ]
        borders = {'top': True}

    class band_detail(ReportBand):
        auto_expand_height = True
        elements = [
            ObjectValue(attribute_name='nome', left=0*cm, width=11*cm,
                  style={'alignment':TA_CENTER}, borders={'top': True}),
            ObjectValue(attribute_name='matricula', left=11.1*cm, width=4*cm,
                  style={'alignment':TA_CENTER}, borders={'top': True}),
            ObjectValue(attribute_name='descricao', left=15.2*cm, width=3.8*cm,
                  style={'alignment':TA_CENTER}, borders={'top': True}),
        ]